﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Math2
{

	public static float clampFloat(float currentVar, float minVar, float maxVar)
	{
		if (currentVar > maxVar)
			return maxVar;
		else if (currentVar < minVar)
			return minVar;
		return currentVar;
	}

	public static float toRadian(float angle)
	{
		return (angle * 3.14f / 180.0f);
	}
	public static float sqrtEx(float sum)
	{
		float i = (sum / 2);

		for (float isb = 0; isb < 10; isb++)
		{
			i = (i - ((i * i - sum) / (2 * i)));
		}
		return i;

	}

	public static float getBeizeri(float var1, float var2, float p0, float p1, float p2, float p3)
	{
		float t = var1 / var2;
		float t1 = 1.0f - t;

		float v1 = t1 * t1 * t1;
		float v2 = t1 * t1;
		float v3 = t1;
		float v4 = t * t * t;

		float ret = p0 * v1;
		ret = ret + 3.0f * p1 * t * v2;
		ret = ret + 3.0f * p2 * t * t * v3;
		ret = ret + p3 * v4;

		return ret;
	}

	public static float sq_BeizeriAngle(float var1, float var2, float p0, float p1, float p2, float p3)
	{
		return 0.0f;
	}

	public static float getParabola(float offsetX,float parabolaHeight,float maxVarX)
	{
		float a = (-parabolaHeight * 4) / (maxVarX * maxVarX);
		return a * (offsetX - maxVarX / 2) * (offsetX - maxVarX / 2) + parabolaHeight;
	}


	public static float sq_ParabolaAngle(float parabolaHeight, float maxVarX)
	{
		float a = (-parabolaHeight * 4) / (maxVarX * maxVarX);
		float v = (2 * a);
		return Mathf.Atan(v);
	}


	public static bool isInRange(float v1, float v2, float v3)
	{
		float minV = Mathf.Min(v1, v2);
		float maxV = v1 + v2 - minV;

		if (v3 > minV && v3 < maxV)
			return true;
		return false;

	}


	public static bool random(float v1, float v2, float v3)
	{

		float rand = Random.Range(v1, v2);
		if (rand > v3)
			return true;
		return false;
	}


	public static float getDistance(ActiveObject obj1, ActiveObject obj2)
	{
		float offsetX = obj1.getXPos() - obj2.getXPos();
		float offsetY = obj1.getYPos() - obj2.getYPos();

		float dist = Mathf.Sqrt(offsetX * offsetX + offsetY * offsetY);
		return dist;

	}

}